package com.person.webdemoproject2.controller;



import com.person.webdemoproject2.pojo.Result;
import com.person.webdemoproject2.service.DeleteService;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@Slf4j
@RequestMapping("/delete")
public class DeleteController {
    @Autowired
    DeleteService deleteService;

    @DeleteMapping("/{postid}/post")
    public Result deletePost(@PathVariable Integer postid, @RequestHeader String token) {
        log.info("用户删除帖子 {}",postid);

        boolean b = deleteService.deletePost(postid, token);

        if (b){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }
    @DeleteMapping("/{CommentId}/comment")
    public Result deleteComment(@PathVariable Integer CommentId, @RequestHeader String token) {
        log.info("用户删除评论 {}",CommentId);

        boolean b = deleteService.deleteComment(token,CommentId);

        if (b){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }
    @DeleteMapping("/user")
    public Result deleteUser(@RequestHeader String token,@RequestParam String password) {
        log.info("用户注销账号");

        boolean b = deleteService.deleteUser(token,password);
        if (b){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }
    @DeleteMapping("/{postid}/collect")
    public Result deleteCollection(@RequestHeader String token,@PathVariable Integer postid) {
        log.info("用户删除收藏");
        boolean b = deleteService.deleteCollection(token,postid);
        if (b){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }
}
